package ln.frame.prac.microprofile.config.source;

import org.eclipse.microprofile.config.spi.ConfigSource;

import java.util.Comparator;

/**
 * {@link ConfigSource}优先级比较器
 */
public class ConfigSourceOrdinalComparator implements Comparator<ConfigSource> {

    // 单例
    public final static ConfigSourceOrdinalComparator INSTANCE = new ConfigSourceOrdinalComparator();

    private ConfigSourceOrdinalComparator() {}

    /**
     * 优先级比较，大的优先
     * @param o1 the first object to be compared.
     * @param o2 the second object to be compared.
     * @return
     */
    @Override
    public int compare(ConfigSource o1, ConfigSource o2) {
        return Integer.compare(o2.getOrdinal(), o1.getOrdinal());
    }

}
